import globals from 'globals'
import pluginJs from '@eslint/js'
import pluginVue from 'eslint-plugin-vue'

import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'

export default [
  {
    languageOptions: { globals: { ...globals.browser, ...globals.node } }
  },
  pluginJs.configs.recommended,
  eslintPluginPrettierRecommended,
  ...pluginVue.configs['flat/essential'],
  {
    languageOptions: {
      // parser: parserVue,
      globals: {
        AMap: true
      },
      parserOptions: {
        parser: '@babel/eslint-parser',
        sourceType: 'module',
        ecmaVersion: 12,
        ecmaFeatures: {
          modules: true,
          legacyDecorators: true
        },
        requireConfigFile: false, // 解决报错：vue--Parsing error: No Babel config file detected for
        extends: ['plugin:prettier/recommended']
      }
    }
  },
  {
    /*
     * eslint规则
     * "off" 或 0    ==>  关闭规则
     * "warn" 或 1   ==>  打开的规则作为警告（不影响代码执行）
     * "error" 或 2  ==>  规则作为一个错误（代码不能执行，界面报错）
     */
    rules: {
      'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
      'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
      'prettier/prettier': 'off',
      'no-cond-assign': ['error', 'always'],
      //关闭组件命名规则
      'vue/multi-word-component-names': 'off',
      'no-constant-condition': [
        'error',
        {
          checkLoops: true
        }
      ],
      'vue/no-ref-as-operand': 'off',
      'no-control-regex': ['error'],
      'no-dupe-args': ['error'],
      'no-dupe-keys': ['error'],
      'no-duplicate-case': ['error'],
      'no-empty': [
        'error',
        {
          allowEmptyCatch: true
        }
      ],
      'no-empty-character-class': ['error'],
      'no-ref-as-operand': ['off'],
      'no-ex-assign': ['error'],
      'no-extra-boolean-cast': ['error'],
      'no-extra-semi': 'off',
      'no-func-assign': ['warn'],
      'no-inner-declarations': ['error'],
      'no-invalid-regexp': [
        'error',
        {
          allowConstructorFlags: []
        }
      ],
      'no-irregular-whitespace': ['error'],
      'no-obj-calls': ['error'],
      'no-regex-spaces': ['error'],
      'no-sparse-arrays': ['error'],
      'no-unexpected-multiline': ['error'],
      'no-unsafe-finally': ['error'],
      'no-unsafe-negation': ['error'],
      'use-isnan': ['error'],
      'default-case': ['error'],
      'dot-notation': ['error'],
      eqeqeq: ['warn'],
      'no-caller': ['error'],
      'no-case-declarations': ['error'],
      'no-empty-function': ['error'],
      'no-empty-pattern': 'off',
      'no-eval': ['error'],
      'no-global-assign': ['error'],
      'no-redeclare': [
        'error',
        {
          builtinGlobals: true
        }
      ],
      'no-self-assign': [
        'error',
        {
          props: true
        }
      ],
      'no-unused-labels': ['error'],
      'no-useless-escape': ['error'],
      radix: 'off',
      'no-delete-var': ['error'],
      'no-undef': ['error'],
      'no-unused-vars': ['error'],
      'no-use-before-define': ['error'],
      'arrow-spacing': [
        'error',
        {
          before: true,
          after: true
        }
      ],
      'no-var': ['error'],
      'object-shorthand': ['error', 'always'],
      'prefer-arrow-callback': [
        'error',
        {
          allowNamedFunctions: false
        }
      ]
    }
  }
]
